<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>ES6+ | fengrixin</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/favicon.ico">
    <script>
         (function(){
            var html = document.createElement('script');
            html.src = 'https://www.googletagmanager.com/gtag/js?id=UA-166891571-1';
            var script = document.getElementsByTagName('script')[0]'
            script.parentNode.insertBefore(html, script);
            
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments)}
            gtag('js', new Date());
            gtag('config', 'UA-166891571-1');
         })();
        </script>
    <meta name="description" content="I don't know anything with certainty, but seeing the stars makes me dream.">
    <meta name="keywords" content="冯日新, fengrixin, rixin, 飘渺云轩">
    <meta name="author" content="rixin, s2675563468, fengrixin@yeah.net">
    <meta name="copyright" content="rixin">
    <meta name="renderer" content="webkit">
    
    <link rel="preload" href="/assets/css/0.styles.52cdc27a.css" as="style"><link rel="preload" href="/assets/js/app.0696c23a.js" as="script"><link rel="preload" href="/assets/js/2.96f039f8.js" as="script"><link rel="preload" href="/assets/js/16.25b14741.js" as="script"><link rel="prefetch" href="/assets/js/10.473b7d15.js"><link rel="prefetch" href="/assets/js/11.0c193dec.js"><link rel="prefetch" href="/assets/js/12.c4d9d484.js"><link rel="prefetch" href="/assets/js/13.dce50cfa.js"><link rel="prefetch" href="/assets/js/14.eecb5cc3.js"><link rel="prefetch" href="/assets/js/15.e0473034.js"><link rel="prefetch" href="/assets/js/17.c016c8f3.js"><link rel="prefetch" href="/assets/js/18.71195568.js"><link rel="prefetch" href="/assets/js/19.1dfd44c0.js"><link rel="prefetch" href="/assets/js/20.abde37ca.js"><link rel="prefetch" href="/assets/js/21.af59917b.js"><link rel="prefetch" href="/assets/js/22.d2f7b52b.js"><link rel="prefetch" href="/assets/js/23.ec5c07a5.js"><link rel="prefetch" href="/assets/js/24.eae97f7d.js"><link rel="prefetch" href="/assets/js/25.2f09818a.js"><link rel="prefetch" href="/assets/js/26.7ae2d77c.js"><link rel="prefetch" href="/assets/js/27.a3963c70.js"><link rel="prefetch" href="/assets/js/28.eadcc4e5.js"><link rel="prefetch" href="/assets/js/29.61cf8d1d.js"><link rel="prefetch" href="/assets/js/3.dd8204a7.js"><link rel="prefetch" href="/assets/js/30.7db889fa.js"><link rel="prefetch" href="/assets/js/31.fb075f3c.js"><link rel="prefetch" href="/assets/js/4.cf123337.js"><link rel="prefetch" href="/assets/js/5.abe0fc83.js"><link rel="prefetch" href="/assets/js/6.d9ded6eb.js"><link rel="prefetch" href="/assets/js/7.a054e416.js"><link rel="prefetch" href="/assets/js/8.f0b3a07f.js"><link rel="prefetch" href="/assets/js/9.f6495dca.js">
    <link rel="stylesheet" href="/assets/css/0.styles.52cdc27a.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">fengrixin</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="地基" class="dropdown-title"><span class="title">地基</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/learn/algorithm/" class="nav-link">数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/learn/browser/" class="nav-link">浏览器工作原理</a></li><li class="dropdown-item"><!----> <a href="/learn/js/es6.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">JavaScript</a></li><li class="dropdown-item"><!----> <a href="/learn/css/" class="nav-link">CSS</a></li><li class="dropdown-item"><!----> <a href="/learn/html/" class="nav-link">HTML</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="楼层" class="dropdown-title"><span class="title">楼层</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/learn/vue/" class="nav-link">Vue</a></li><li class="dropdown-item"><!----> <a href="/learn/node/" class="nav-link">Node.js</a></li><li class="dropdown-item"><!----> <a href="/learn/mini/index.html" class="nav-link">小程序</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="电梯" class="dropdown-title"><span class="title">电梯</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/learn/tools/chain.html" class="nav-link">工具链</a></li><li class="dropdown-item"><!----> <a href="/learn/tools/publish.html" class="nav-link">发布系统</a></li><li class="dropdown-item"><!----> <a href="/learn/tools/monitor.html" class="nav-link">监控系统</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="看一看" class="dropdown-title"><span class="title">看一看</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>仓库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/watch/repository.html" class="nav-link">第三方库</a></li><li class="dropdown-subitem"><a href="/watch/website.html" class="nav-link">好玩的网站</a></li><li class="dropdown-subitem"><a href="/watch/article.html" class="nav-link">牛掰的文章</a></li><li class="dropdown-subitem"><a href="/watch/plugin.html" class="nav-link">扩展&amp;插件</a></li></ul></li><li class="dropdown-item"><h4>作品</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="http://www.5you.com/apk/384161.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  微冷知识
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><a href="https://github.com/fengrixin" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="地基" class="dropdown-title"><span class="title">地基</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/learn/algorithm/" class="nav-link">数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/learn/browser/" class="nav-link">浏览器工作原理</a></li><li class="dropdown-item"><!----> <a href="/learn/js/es6.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">JavaScript</a></li><li class="dropdown-item"><!----> <a href="/learn/css/" class="nav-link">CSS</a></li><li class="dropdown-item"><!----> <a href="/learn/html/" class="nav-link">HTML</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="楼层" class="dropdown-title"><span class="title">楼层</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/learn/vue/" class="nav-link">Vue</a></li><li class="dropdown-item"><!----> <a href="/learn/node/" class="nav-link">Node.js</a></li><li class="dropdown-item"><!----> <a href="/learn/mini/index.html" class="nav-link">小程序</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="电梯" class="dropdown-title"><span class="title">电梯</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/learn/tools/chain.html" class="nav-link">工具链</a></li><li class="dropdown-item"><!----> <a href="/learn/tools/publish.html" class="nav-link">发布系统</a></li><li class="dropdown-item"><!----> <a href="/learn/tools/monitor.html" class="nav-link">监控系统</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="看一看" class="dropdown-title"><span class="title">看一看</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>仓库</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/watch/repository.html" class="nav-link">第三方库</a></li><li class="dropdown-subitem"><a href="/watch/website.html" class="nav-link">好玩的网站</a></li><li class="dropdown-subitem"><a href="/watch/article.html" class="nav-link">牛掰的文章</a></li><li class="dropdown-subitem"><a href="/watch/plugin.html" class="nav-link">扩展&amp;插件</a></li></ul></li><li class="dropdown-item"><h4>作品</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="http://www.5you.com/apk/384161.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  微冷知识
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></li></ul></div></div><div class="nav-item"><a href="https://github.com/fengrixin" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/learn/js/es6.html" aria-current="page" class="active sidebar-link">ES6+</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#变量类型" class="sidebar-link">变量类型</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#array" class="sidebar-link">Array</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#增删改查" class="sidebar-link">增删改查</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#遍历" class="sidebar-link">遍历</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#转换" class="sidebar-link">转换</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#原地处理并返回" class="sidebar-link">原地处理并返回</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#处理并返回新数组" class="sidebar-link">处理并返回新数组</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#iterator" class="sidebar-link">Iterator</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#初始化数组" class="sidebar-link">初始化数组</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#string" class="sidebar-link">String</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#同-array" class="sidebar-link">同 Array</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#转换-2" class="sidebar-link">转换</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#原地处理字符串" class="sidebar-link">原地处理字符串</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#处理返回新字符串" class="sidebar-link">处理返回新字符串</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#还在为补-0-苦恼吗" class="sidebar-link">还在为补 0 苦恼吗？</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#object" class="sidebar-link">Object</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#object-defineproperty" class="sidebar-link">Object.defineProperty</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#object-getownpropertydescriptor" class="sidebar-link">Object.getOwnPropertyDescriptor</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#object-getpropertyof" class="sidebar-link">Object.getPropertyOf</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#object-assign" class="sidebar-link">Object.assign</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#冻结对象" class="sidebar-link">冻结对象</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#_0等于-0-nan不等于nan" class="sidebar-link">-0等于+0？ NaN不等于NaN？</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#function" class="sidebar-link">Function</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#内部属性" class="sidebar-link">内部属性</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#bind、apply-call" class="sidebar-link">bind、apply &amp; call</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#参数" class="sidebar-link">参数</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#箭头函数" class="sidebar-link">箭头函数</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#number" class="sidebar-link">Number</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#判断整型" class="sidebar-link">判断整型</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#number-和-parseint-的区别" class="sidebar-link">Number 和 parseInt 的区别</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#tofixed-n" class="sidebar-link">toFixed(n)</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#_0-1-0-2-0-3" class="sidebar-link">0.1+0.2!==0.3</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#date" class="sidebar-link">Date</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#set" class="sidebar-link">Set</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#map" class="sidebar-link">Map</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#symbol" class="sidebar-link">Symbol</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#promise" class="sidebar-link">Promise</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#all" class="sidebar-link">all([])</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#allsettled" class="sidebar-link">allSettled([])</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#race" class="sidebar-link">race([])</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#手写-promise" class="sidebar-link">手写 Promise</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#proxy" class="sidebar-link">Proxy</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#reflect" class="sidebar-link">Reflect</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/learn/js/es6.html#ownkeys" class="sidebar-link">ownKeys</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#has" class="sidebar-link">has</a></li></ul></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#generator" class="sidebar-link">Generator</a></li><li class="sidebar-sub-header"><a href="/learn/js/es6.html#iterator-2" class="sidebar-link">Iterator</a></li></ul></li><li><a href="/learn/js/point.html" class="sidebar-link">知识点</a></li><li><a href="/learn/js/tools.html" class="sidebar-link">工具方法</a></li><li><a href="/learn/js/typescript.html" class="sidebar-link">TypeScript</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><blockquote><p>参考来源：
<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript" target="_blank" rel="noopener noreferrer">MDN<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 、
<a href="https://es6.ruanyifeng.com" target="_blank" rel="noopener noreferrer">《ES6 入门教程 - 阮一峰》<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 、
<a href="https://time.geekbang.org/column/article/83302" target="_blank" rel="noopener noreferrer">《重学前端》<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 、
<a href="https://time.geekbang.org/column/article/119046" target="_blank" rel="noopener noreferrer">《浏览器工作原理与实践》<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></blockquote> <h2 id="变量类型"><a href="#变量类型" class="header-anchor">#</a> 变量类型</h2> <p><img src="https://static001.geekbang.org/resource/image/85/15/85b87602eac65356c9171bbd023f5715.png" alt=""></p> <table><thead><tr><th></th> <th style="text-align:center;"></th> <th style="text-align:center;"></th> <th style="text-align:center;"></th> <th style="text-align:center;"></th> <th style="text-align:center;"></th> <th style="text-align:center;"></th> <th style="text-align:right;"></th></tr></thead> <tbody><tr><td>值类型</td> <td style="text-align:center;">String</td> <td style="text-align:center;">Number</td> <td style="text-align:center;">Boolean</td> <td style="text-align:center;">Undefined</td> <td style="text-align:center;">Null</td> <td style="text-align:center;">Symbol</td> <td style="text-align:right;">BigInt</td></tr> <tr><td>引用类型</td> <td style="text-align:center;">Object</td> <td style="text-align:center;">Function</td> <td style="text-align:center;">Array</td> <td style="text-align:center;">Map</td> <td style="text-align:center;">Set</td> <td style="text-align:center;"></td> <td style="text-align:right;"></td></tr></tbody></table> <h2 id="array"><a href="#array" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array" target="_blank" rel="noopener noreferrer">Array<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h3 id="增删改查"><a href="#增删改查" class="header-anchor">#</a> 增删改查</h3> <h4 id="增"><a href="#增" class="header-anchor">#</a> 增</h4> <ul><li>push：向数组末尾添加一个或多个元素，并返回新长度</li> <li>unshift：向数组头部添加一个或多个元素，并返回新长度</li></ul> <h4 id="删"><a href="#删" class="header-anchor">#</a> 删</h4> <ul><li>pop：删除数组最后一个元素，并返回删除元素</li> <li>shift：删除数组第一个元素，并返回删除元素</li></ul> <h4 id="改"><a href="#改" class="header-anchor">#</a> 改</h4> <ul><li>fill：给数组填充一个固定值（可以给定开始结束位置）</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token comment">// 创建一个长度为 5 初始值为 0 的数组</span>
<span class="token function">Array</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">fill</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment">//[0,0,0,0,0]</span>
</code></pre></div><h4 id="查"><a href="#查" class="header-anchor">#</a> 查</h4> <ul><li>includes：查询数组中是否包含指定的值，有则返回 true（注意：引用类型除外）</li> <li>indexOf：查询元素在数组中首次出现的位置，没有则返回 -1</li> <li>lastIndexOf：查询元素在数组中最后一次出现的位置，没有则返回 -1</li> <li>find：遍历数组，返回第一个满足条件的值，否则返回 undefined</li> <li>findIndex：遍历数组，返回第一个满足条件的索引，否则返回 -1</li> <li>some：遍历数组，判断数组至少一项是否满足条件，返回 true / false</li> <li>every：遍历数组，判断数组全部元素是否满足条件，返回 true / false</li></ul> <h3 id="遍历"><a href="#遍历" class="header-anchor">#</a> 遍历</h3> <blockquote><p>看具体场景使用</p></blockquote> <ul><li>for in：key(也就是 index)</li> <li>for of：value</li> <li>forEach：index，value，原数组</li></ul> <h3 id="转换"><a href="#转换" class="header-anchor">#</a> 转换</h3> <ul><li>join：将数组元素转换成字符串（默认以逗号分隔）</li></ul> <h3 id="原地处理并返回"><a href="#原地处理并返回" class="header-anchor">#</a> 原地处理并返回</h3> <ul><li>push、pop、unshift、shift</li> <li>splice：可对数组进行添加、替换、删除</li> <li>sort：对数组进行排序</li> <li>reverse：反转数组</li></ul> <h3 id="处理并返回新数组"><a href="#处理并返回新数组" class="header-anchor">#</a> 处理并返回新数组</h3> <blockquote><p>返回的新数组都是浅拷贝</p></blockquote> <ul><li>concat：合并两个或多个数组</li> <li>slice：切割数组</li> <li>map：遍历数组，对每一项进行处理</li> <li>filter：遍历数组，对数组进行筛选，剔除不符合条件的 item</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">const</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span>
arr<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token parameter">item</span><span class="token operator">=&gt;</span>item<span class="token operator">!==</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment">// [1, 3, 4]</span>
</code></pre></div><ul><li>flat：深度遍历，返回给定层数的新数组</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">const</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
arr<span class="token punctuation">.</span><span class="token function">flat</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment">// [1,2,3,4,5,6]</span>
</code></pre></div><h3 id="iterator"><a href="#iterator" class="header-anchor">#</a> Iterator</h3> <blockquote><p>返回一个新的 Array Iterator 对象</p></blockquote> <ul><li>entries：包含键值对</li> <li>keys：只包含索引</li> <li>values：只包含值</li></ul> <h3 id="初始化数组"><a href="#初始化数组" class="header-anchor">#</a> 初始化数组</h3> <ul><li>Array.from</li></ul> <blockquote><p>可以将类数组转换为数组 <br> <a href="https://www.imooc.com/article/48944" target="_blank" rel="noopener noreferrer">类数组<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>：arguments、document.querySelector 的值、string</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code>Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span><span class="token string">'rixin'</span><span class="token punctuation">)</span> <span class="token comment">// ['r','i','x','i','n']</span>

<span class="token comment">// 创建一个长度为 5 且初始值为 0 的数组</span>
Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span><span class="token punctuation">{</span>length<span class="token operator">:</span><span class="token number">5</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment">// [0,0,0,0,0]</span>

<span class="token comment">// 创建一个长度为 5 且初始值为 1-5 的数组</span>
Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span><span class="token function">Array</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">fill</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">v<span class="token punctuation">,</span>i</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">// [1,2,3,4,5]</span>
</code></pre></div><ul><li>Array.of</li></ul> <blockquote><p>创建数组，一个参数对应一个值</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code>Array<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token comment">// [5]</span>
Array<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span> <span class="token comment">// [1,2,3]</span>
</code></pre></div><h2 id="string"><a href="#string" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String" target="_blank" rel="noopener noreferrer">String<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <blockquote><p>String 和 Array 很多属性方法都差不多，毕竟它俩可以互相转换</p></blockquote> <h3 id="同-array"><a href="#同-array" class="header-anchor">#</a> 同 Array</h3> <ul><li>length</li> <li>includes：查询是否存在某个字符串，返回 true/false</li> <li>indexOf：查询是否存在某个字符串，返回字符串的索引，否则 -1</li> <li>lastIndexOf：从后往前查询，返回值同上</li> <li>concat</li> <li>slice</li></ul> <h3 id="转换-2"><a href="#转换-2" class="header-anchor">#</a> 转换</h3> <ul><li>split：将字符串以特定字符切割成数组返回</li></ul> <h3 id="原地处理字符串"><a href="#原地处理字符串" class="header-anchor">#</a> 原地处理字符串</h3> <p>无</p> <h3 id="处理返回新字符串"><a href="#处理返回新字符串" class="header-anchor">#</a> 处理返回新字符串</h3> <ul><li>concat：连接字符串</li> <li>repeat：将字符串重复（整数次）</li> <li>replace：替换字符串（可正则替换）</li> <li>slice：剪切字符串（接受负数，开始结束坐标固定）</li> <li>substring：剪切字符串（负数会转换为 0，哪个参数小哪个就是开始坐标）</li> <li>toLocalLowerCase：转化成小写（加上 Local 稳妥一些，一些特定地区的转化比较特殊）</li> <li>toLocalUpperCase：转化成大写</li> <li>trim：两端去空白</li> <li>trimStart：开头去空白</li> <li>trimRight：末尾去空白</li> <li>padStart：开头补白</li> <li>padEnd：末尾补白</li></ul> <h3 id="还在为补-0-苦恼吗"><a href="#还在为补-0-苦恼吗" class="header-anchor">#</a> 还在为补 0 苦恼吗？</h3> <p>以往，对于日期补 0，往往需要这样子</p> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">formatZero</span><span class="token punctuation">(</span><span class="token parameter">num<span class="token punctuation">,</span> length</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">(</span><span class="token function">Array</span><span class="token punctuation">(</span>length<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">'0'</span><span class="token punctuation">)</span> <span class="token operator">+</span> num<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token operator">-</span>length<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">formatZero</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment">// 03</span>
</code></pre></div><p>ES8 之后，增加了这两个 API（对 String 补白的方式）</p> <ul><li>padStart</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'3'</span><span class="token punctuation">.</span><span class="token function">padStart</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">'0'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 03</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'3'</span><span class="token punctuation">.</span><span class="token function">padStart</span><span class="token punctuation">(</span><span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">'#&amp;'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// #&amp;#&amp;#3</span>
</code></pre></div><ul><li>padEnd</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'3'</span><span class="token punctuation">.</span><span class="token function">padEnd</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">'0'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token comment">// 30</span>
</code></pre></div><h2 id="object"><a href="#object" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object" target="_blank" rel="noopener noreferrer">Object<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <p>在 JS 运行时，原生对象的描述方式非常简单，我们只需要关心原型和属性两个部分</p> <ul><li>属性：数据属性、访问器属性
<blockquote><p>JS 用属性来统一抽象对象状态和行为。一般来说，数据属性用于描述状态，访问器属性则用于描述行为。但数据属性中如果存储函数，也可以用于描述行为。</p></blockquote> <ul><li>数据属性：[[value]]、writable、enumerable、configurable</li> <li>访问器属性：get、set、enumerable、configurable</li></ul></li> <li>原型： <a href="/learn/js/point.html#原型-原型链">传送门</a></li></ul> <h3 id="object-defineproperty"><a href="#object-defineproperty" class="header-anchor">#</a> Object.defineProperty</h3> <p>给对象新增/修改一个属性，并指定属性的配置</p> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
Object<span class="token punctuation">.</span><span class="token function">defineProperty</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> <span class="token string">'key'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    configurable<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// true-可更改该属性名或删除该defineProperty 时属性通过 ，默新增认 false</span>
    enumerable<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// true-可枚举该属性，通过 defineProperty 新增时默认 false</span>
    writable<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// true-可修改该属性值，通过 defineProperty 新增时默认 false</span>
    value<span class="token operator">:</span> <span class="token string">'value'</span><span class="token punctuation">,</span>
    <span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">set</span><span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token comment">// {key: 'value'}</span>
</code></pre></div><blockquote><p>Object.defineProperties 增强版，可新增/修改多个属性</p></blockquote> <h3 id="object-getownpropertydescriptor"><a href="#object-getownpropertydescriptor" class="header-anchor">#</a> Object.getOwnPropertyDescriptor</h3> <p>获取属性的 props(配置)</p> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>key<span class="token operator">:</span> <span class="token string">'value'</span><span class="token punctuation">}</span>
Object<span class="token punctuation">.</span><span class="token function">getOwnPropertyDescriptor</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> <span class="token string">'key'</span><span class="token punctuation">)</span>
<span class="token comment">// {configurable: false, enumerable: false,writable: false,value: 'value',get() {},set(v) {}} </span>
</code></pre></div><blockquote><p>getOwnPropertyDescriptors 增强版，获取对象所有属性的 props</p></blockquote> <h3 id="object-getpropertyof"><a href="#object-getpropertyof" class="header-anchor">#</a> Object.getPropertyOf</h3> <p>返回对象的原型</p> <h3 id="object-assign"><a href="#object-assign" class="header-anchor">#</a> Object.assign</h3> <p>追加/合并属性，经常用于浅拷贝。</p> <blockquote><p>将一个或多个对象与目标对象合并，目标对象已经存在的，即覆盖，不存在的，即追加 <br>
操作后会原地改变目标对象，并返回目标对象</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">let</span> target <span class="token operator">=</span> <span class="token punctuation">{</span>a<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> b<span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">}</span>
Object<span class="token punctuation">.</span><span class="token function">assign</span><span class="token punctuation">(</span>target<span class="token punctuation">,</span> <span class="token punctuation">{</span>b<span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span> c<span class="token operator">:</span><span class="token number">4</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token comment">// {a: 1, b: 3, c: 4}</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>target<span class="token punctuation">)</span> <span class="token comment">// {a: 1, b: 3, c: 4}</span>
</code></pre></div><p>通过该方法浅拷贝，只能拷贝源对象的可枚举属性，且属性的 prop 配置将会重置为普通数据属性，也无法拷贝源对象的原型</p> <blockquote><p>可使用以下方法实现拷贝不可枚举属性、props、原型</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code>Object<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span>Object<span class="token punctuation">.</span><span class="token function">getPrototypeOf</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">,</span> Object<span class="token punctuation">.</span><span class="token function">getOwnPropertyDescriptors</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="冻结对象"><a href="#冻结对象" class="header-anchor">#</a> 冻结对象</h3> <p><strong>Object.freeze()</strong> 对源对象进行冻结，对象被冻结后，不可增删改</p> <blockquote><p>Object.isFrozen  判断是否被冻结 <br>
Object.preventExtensions  把对象变为不可扩展 <br>
Object.isExtensible  判断是否可扩展 <br>
Object.seal  把对象封闭起来 <br>
Object.isSealed  判断是否被密封 <br></p></blockquote> <h3 id="_0等于-0-nan不等于nan"><a href="#_0等于-0-nan不等于nan" class="header-anchor">#</a> -0等于+0？ NaN不等于NaN？</h3> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token operator">-</span><span class="token number">0</span> <span class="token operator">===</span> <span class="token operator">+</span><span class="token number">0</span>  <span class="token comment">// true</span>
<span class="token number">NaN</span> <span class="token operator">===</span> <span class="token number">NaN</span>  <span class="token comment">// false</span>
</code></pre></div><p>对于以上这种情况，可以使用 <strong>Object.is(v1, v2)</strong></p> <div class="language-javascript extra-class"><pre class="language-javascript"><code>Object<span class="token punctuation">.</span><span class="token function">is</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>  <span class="token comment">// false</span>
Object<span class="token punctuation">.</span><span class="token function">is</span><span class="token punctuation">(</span><span class="token number">NaN</span><span class="token punctuation">,</span> <span class="token number">NaN</span><span class="token punctuation">)</span>  <span class="token comment">// true</span>
</code></pre></div><h2 id="function"><a href="#function" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function" target="_blank" rel="noopener noreferrer">Function<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <p>在函数内部，有两个特殊的对象：arguments 和 this</p> <ul><li>arguments：类数组，主要用途是用来保存函数参数。
<blockquote><p>它还有一个名叫 callee 的属性，该属性是一个指针，指向拥有这个 arguments 对象的函数。严格模式下会报错<br>
一般在函数内部调用自身的时候使用它会更好。因为消除了耦合度，修改函数名时不需要进一步修改内部</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code> <span class="token keyword">function</span> <span class="token function">factorial</span><span class="token punctuation">(</span><span class="token parameter">num</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>num <span class="token operator">&lt;=</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token number">1</span><span class="token punctuation">;</span>
      <span class="token keyword">return</span> num <span class="token operator">*</span> arguments<span class="token punctuation">.</span><span class="token function">callee</span><span class="token punctuation">(</span>num <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span>
 <span class="token punctuation">}</span>
</code></pre></div></li> <li>this：<a href="/learn/js/point.html#this">点击传送</a></li></ul> <h3 id="内部属性"><a href="#内部属性" class="header-anchor">#</a> 内部属性</h3> <p>每个函数都包含两个属性：length 和 prototype（bind 返回的函数和箭头函数则没有 prototype）</p> <ul><li>length：返回函数希望接收的命名参数个数（默认值和可变参数不会统计）</li> <li>prototype：对于引用类型而言，prototype 是保存它们所有实例方法和属性的真正所在。</li></ul> <h3 id="bind、apply-call"><a href="#bind、apply-call" class="header-anchor">#</a> bind、apply &amp; call</h3> <ul><li>相同点：给函数传递一个指定的 <a href="/learn/js/point.html#this">this</a>，皆以第一个参数传递</li> <li>不同点：
<ul><li>bind 和 call 接受的是参数列表，apply 接受的是参数数组</li> <li>apply 和 call 的返回值是函数执行后的返回值（没有则返回 undefined） <br>
bind 的返回值是原函数的拷贝，并拥有指定的 this 和传递的参数。如果返回的函数重新 new，this 会被忽略掉。</li></ul></li></ul> <h3 id="参数"><a href="#参数" class="header-anchor">#</a> 参数</h3> <blockquote><p>函数的参数是函数内部的局部变量</p></blockquote> <ul><li>默认值参数</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token punctuation">,</span> y<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">,</span> z</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> y<span class="token punctuation">,</span> z<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// undefined 2 undefined</span>
</code></pre></div><ul><li>可变参数</li></ul> <blockquote><p>可变参数后不可再有其他参数</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token punctuation">,</span> <span class="token operator">...</span>params</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>x<span class="token punctuation">,</span> params<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token comment">// 1 [2, 3, 4]</span>
</code></pre></div><ul><li>传参-拆开数组</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">fn</span><span class="token punctuation">(</span><span class="token parameter">x<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> y<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">,</span> z<span class="token operator">=</span><span class="token number">3</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>x<span class="token operator">+</span>y<span class="token operator">+</span>z<span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment">// 9</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment">// 12</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment">// 15</span>
</code></pre></div><h3 id="箭头函数"><a href="#箭头函数" class="header-anchor">#</a> 箭头函数</h3> <blockquote><p>在箭头函数中，this 指向属于外层作用域。因为箭头函数并不会创建其自身的执行上下文</p></blockquote> <div class="language-javascript extra-class"><pre class="language-javascript"><code>window<span class="token punctuation">.</span>x <span class="token operator">=</span> <span class="token number">2</span>
<span class="token keyword">const</span> <span class="token function-variable function">fn</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">x</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>x <span class="token operator">+</span> <span class="token number">1</span>
<span class="token punctuation">}</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">// 3</span>
</code></pre></div><h4 id="注意事项"><a href="#注意事项" class="header-anchor">#</a> 注意事项</h4> <ul><li>如果返回值是表达式，可省略 return 和 {}</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">const</span> <span class="token function-variable function">fn</span> <span class="token operator">=</span> <span class="token parameter">x</span> <span class="token operator">=&gt;</span> x<span class="token operator">+</span><span class="token number">1</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">// 2</span>
</code></pre></div><ul><li>如果返回值是对象，需要用括号包起来</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">const</span> <span class="token function-variable function">fn</span> <span class="token operator">=</span> <span class="token parameter">x</span> <span class="token operator">=&gt;</span> <span class="token punctuation">(</span><span class="token punctuation">{</span>x<span class="token operator">:</span> x<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token function">fn</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">// {x: 2}</span>
</code></pre></div><h2 id="number"><a href="#number" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number" target="_blank" rel="noopener noreferrer">Number<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h3 id="判断整型"><a href="#判断整型" class="header-anchor">#</a> 判断整型</h3> <div class="language-javascript extra-class"><pre class="language-javascript"><code>Number<span class="token punctuation">.</span><span class="token function">isInteger</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">//true</span>
</code></pre></div><h3 id="number-和-parseint-的区别"><a href="#number-和-parseint-的区别" class="header-anchor">#</a> Number 和 parseInt 的区别</h3> <p>如无必要，一般选择 Number</p> <ul><li>Number 可格式化浮点数，parseInt 只能格式化成整数</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token function">Number</span><span class="token punctuation">(</span><span class="token string">'12.34'</span><span class="token punctuation">)</span> <span class="token comment">// 12.34</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'12.34'</span><span class="token punctuation">)</span> <span class="token comment">// 12</span>
</code></pre></div><ul><li>Number 不能格式化带有除数字外的字符串，parseInt 可格式化头部为数字的字符串</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token function">Number</span><span class="token punctuation">(</span><span class="token string">'123abc'</span><span class="token punctuation">)</span> <span class="token comment">// NaN</span>
<span class="token function">parseInt</span><span class="token punctuation">(</span><span class="token string">'123abc'</span><span class="token punctuation">)</span> <span class="token comment">// 123</span>
</code></pre></div><h3 id="tofixed-n"><a href="#tofixed-n" class="header-anchor">#</a> toFixed(n)</h3> <blockquote><p>保留小数点后几位，会四舍五入，默认为 0 ，返回字符串</p></blockquote> <h3 id="_0-1-0-2-0-3"><a href="#_0-1-0-2-0-3" class="header-anchor">#</a> 0.1+0.2!==0.3</h3> <blockquote><p>由于浮点数的精度问题，0.1+0.2=0.30000000000000004 <br>
因此，非整数的 Number 类型无法用 ==/=== 来比较</p></blockquote> <p>正确的比较方法：</p> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">function</span> <span class="token function">equalFloat</span><span class="token punctuation">(</span><span class="token parameter">num</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
 <span class="token keyword">return</span> Math<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span>num<span class="token punctuation">)</span> <span class="token operator">&lt;=</span> Number<span class="token punctuation">.</span><span class="token constant">EPSILON</span>
<span class="token punctuation">}</span>
<span class="token function">equalFloat</span><span class="token punctuation">(</span><span class="token number">0.1</span><span class="token operator">+</span><span class="token number">0.2</span><span class="token operator">-</span><span class="token number">0.3</span><span class="token punctuation">)</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="date"><a href="#date" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date" target="_blank" rel="noopener noreferrer">Date<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <ul><li>Date.now()  当前时间戳</li> <li>Date.prototype.getFullYear()  年份</li> <li>Date.prototype.getMouth()  月份 - 1</li> <li>Date.prototype.getDate()  几号</li> <li>Date.prototype.getDay()  周几，周日是 0</li> <li>Date.prototype.getHours()  几点</li> <li>Date.prototype.getMinutes()  几分</li> <li>Date.prototype.getSeconds()  几秒</li> <li>Date.prototype.getTime() 创建时的时间戳</li></ul> <h2 id="set"><a href="#set" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Set" target="_blank" rel="noopener noreferrer">Set<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <blockquote><p>值集合，且唯一（即不可重复，无论是基本类型或是对象的引用）</p></blockquote> <ul><li>属性：[size]</li> <li>常用方法：[add]  [delete]  [has]  [clear]</li> <li>遍历：[for of] [forEach]</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">let</span> set <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Set</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
set<span class="token punctuation">.</span>size <span class="token comment">// 3</span>
set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">'2'</span><span class="token punctuation">)</span>
set<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token punctuation">{</span>a<span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
set<span class="token punctuation">.</span><span class="token function">delete</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="map"><a href="#map" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Map" target="_blank" rel="noopener noreferrer">Map<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <blockquote><p>键值对集合，因为键可以是任意类型，所以更适合用来替代对象</p></blockquote> <ul><li>属性：[size]</li> <li>常用方法：[set] [get] [delete] [has] [clear]</li> <li>遍历：[for of] [forEach]</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">let</span> map <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Map</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token string">'key'</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
map<span class="token punctuation">.</span>size <span class="token comment">// 2 </span>
map<span class="token punctuation">.</span><span class="token function">set</span><span class="token punctuation">(</span><span class="token string">'key'</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span>
map<span class="token punctuation">.</span><span class="token function">get</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span>
map<span class="token punctuation">.</span><span class="token function">delete</span><span class="token punctuation">(</span><span class="token string">'key'</span><span class="token punctuation">)</span>
</code></pre></div><h2 id="symbol"><a href="#symbol" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Symbol" target="_blank" rel="noopener noreferrer">Symbol<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h2 id="promise"><a href="#promise" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise" target="_blank" rel="noopener noreferrer">Promise<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h3 id="all"><a href="#all" class="header-anchor">#</a> all([])</h3> <p>接受多个 Promise，当所有 Promise 都 resolve 后才 then，当任意一个 Promise reject 时都会立即 catch</p> <h3 id="allsettled"><a href="#allsettled" class="header-anchor">#</a> allSettled([])</h3> <p>接受多个 Promise，返回所有 Promise 的结果，无论是 resolve 还是 reject</p> <h3 id="race"><a href="#race" class="header-anchor">#</a> race([])</h3> <p>接受多个 Promise，当任意一个 Promise resolve/reject 时都会立即 then/catch</p> <h3 id="手写-promise"><a href="#手写-promise" class="header-anchor">#</a> 手写 Promise</h3> <p><a href="https://promisesaplus.com" target="_blank" rel="noopener noreferrer">promise A+<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <ul><li><ol><li>术语：</li></ol> <ul><li>promise：是一个对象或者函数，该对象或函数有一个 then 方法</li> <li>thenable：是一个对象或函数，用来定义 then 方法</li> <li>value：是 promise 状态成功时的值</li> <li>reason：是 promise 状态失败时的值</li></ul></li> <li><ol start="2"><li>要求</li></ol> <ul><li>一个 promise 必须有 3 个状态，pending、fulfilled、rejected。当处于 pending 状态的时候，可以转移到 fulfilled 或者 rejected 状态，当处于 fulfilled 或者 rejected 状态时，不可变。</li> <li>一个 promise 必须有一个 then 方法，then 方法接受两个参数 then(onFulfilled, onRejected)</li> <li>为了实现链式调用，then 方法必须返回一个 promise</li></ul></li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">class</span> <span class="token class-name">MyPromise</span><span class="token punctuation">{</span>
  <span class="token keyword">static</span> pending <span class="token operator">=</span> <span class="token string">'pending'</span>
  <span class="token keyword">static</span> fulfilled <span class="token operator">=</span> <span class="token string">'fulfilled'</span>
  <span class="token keyword">static</span> rejected <span class="token operator">=</span> <span class="token string">'rejected'</span>

  <span class="token function">constructor</span><span class="token punctuation">(</span><span class="token parameter">executor</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">=</span> MyPromise<span class="token punctuation">.</span>pending
    <span class="token keyword">this</span><span class="token punctuation">.</span>value <span class="token operator">=</span> <span class="token keyword">undefined</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>reason <span class="token operator">=</span> <span class="token keyword">undefined</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span>callbacks <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>

    <span class="token keyword">try</span><span class="token punctuation">{</span>
      <span class="token function">executor</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_resolve</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_reject</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token keyword">catch</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_reject</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">onFulfilled<span class="token punctuation">,</span> onRejected</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MyPromise</span><span class="token punctuation">(</span>onNextFulfilled<span class="token punctuation">,</span> onNextRejected<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_handler</span><span class="token punctuation">(</span><span class="token punctuation">{</span>onFulfilled<span class="token punctuation">,</span> onRejected<span class="token punctuation">,</span> onNextFulfilled<span class="token punctuation">,</span> onNextRejected<span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">catch</span><span class="token punctuation">(</span>onRejected<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token keyword">null</span><span class="token punctuation">,</span> onRejected<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">finally</span><span class="token punctuation">(</span>onFinally<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span>onFinally<span class="token punctuation">,</span> onFinally<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">static</span> <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// 如果 value 本身就是一个 Promise，那么就直接返回 value 本身</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>value <span class="token keyword">instanceof</span> <span class="token class-name">MyPromise</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">return</span> value
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MyPromise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token function">resolve</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">static</span> <span class="token function">reject</span><span class="token punctuation">(</span><span class="token parameter">reason</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>reason <span class="token keyword">instanceof</span> <span class="token class-name">MyPromise</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">return</span> reason
    <span class="token punctuation">}</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MyPromise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token function">reject</span><span class="token punctuation">(</span>reason<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">static</span> <span class="token function">all</span><span class="token punctuation">(</span><span class="token parameter">iterable</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
     <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MyPromise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
       <span class="token keyword">const</span> ret <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
       <span class="token keyword">let</span> count <span class="token operator">=</span> <span class="token number">0</span>
       <span class="token comment">// 所有都成功才返回 resolve，一个失败就返回 reject</span>
       Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>iterable<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">item<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
         MyPromise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">data</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
           ret<span class="token punctuation">[</span>index<span class="token punctuation">]</span> <span class="token operator">=</span> data
           count<span class="token operator">++</span>
           <span class="token keyword">if</span><span class="token punctuation">(</span>count<span class="token operator">===</span>iterable<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">{</span>
             <span class="token function">resolve</span><span class="token punctuation">(</span>ret<span class="token punctuation">)</span>
           <span class="token punctuation">}</span>
         <span class="token punctuation">}</span><span class="token punctuation">,</span> reject<span class="token punctuation">)</span>
       <span class="token punctuation">}</span><span class="token punctuation">)</span>
     <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">static</span> <span class="token function">any</span><span class="token punctuation">(</span><span class="token parameter">iterable</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MyPromise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> ret <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
      <span class="token keyword">let</span> count <span class="token operator">=</span> <span class="token number">0</span>
      <span class="token comment">// 所有失败才返回 reject，一个成功就返回 resolve</span>
      Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>iterable<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">item<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        MyPromise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span>resolve<span class="token punctuation">,</span> <span class="token parameter">reason</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
          ret<span class="token punctuation">[</span>index<span class="token punctuation">]</span> <span class="token operator">=</span> reason
          count<span class="token operator">++</span>
          <span class="token keyword">if</span><span class="token punctuation">(</span>count <span class="token operator">===</span> iterable<span class="token punctuation">.</span>length<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token function">reject</span><span class="token punctuation">(</span>ret<span class="token punctuation">)</span>
          <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">static</span> <span class="token function">race</span><span class="token punctuation">(</span><span class="token parameter">iterable</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token comment">// 其中一个成功或失败，就立马返回</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MyPromise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      Array<span class="token punctuation">.</span><span class="token function">from</span><span class="token punctuation">(</span>iterable<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">item</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        MyPromise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span>resolve<span class="token punctuation">,</span> reject<span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>

  <span class="token function">_resolve</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">===</span> MyPromise<span class="token punctuation">.</span>pending<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token comment">// 如果 value 为 Promise 时，说明当前是 then 之后返回的 Promise</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>value <span class="token keyword">instanceof</span> <span class="token class-name">MyPromise</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        value<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_resolve</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_reject</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span>
      <span class="token punctuation">}</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>value <span class="token operator">=</span> value
      <span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">=</span> MyPromise<span class="token punctuation">.</span>fulfilled
      <span class="token keyword">this</span><span class="token punctuation">.</span>callbacks<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">cb</span> <span class="token operator">=&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_handler</span><span class="token punctuation">(</span>cb<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token function">_reject</span><span class="token punctuation">(</span><span class="token parameter">reason</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">===</span> MyPromise<span class="token punctuation">.</span>pending<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">if</span><span class="token punctuation">(</span>reason <span class="token keyword">instanceof</span> <span class="token class-name">MyPromise</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        reason<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_resolve</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_reject</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        <span class="token keyword">return</span>
      <span class="token punctuation">}</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>reason <span class="token operator">=</span> reason
      <span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">=</span> MyPromise<span class="token punctuation">.</span>rejected
      <span class="token keyword">this</span><span class="token punctuation">.</span>callbacks<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">cb</span> <span class="token operator">=&gt;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">_handler</span><span class="token punctuation">(</span>cb<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>

  <span class="token function">_handler</span><span class="token punctuation">(</span><span class="token parameter">callback</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">const</span> <span class="token punctuation">{</span>onFulfilled<span class="token punctuation">,</span> onRejected<span class="token punctuation">,</span> onNextFulfilled<span class="token punctuation">,</span> onRejected<span class="token punctuation">}</span> <span class="token operator">=</span> callback
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">===</span> MyPromise<span class="token punctuation">.</span>pending<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>callbacks<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>callback<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">===</span> MyPromise<span class="token punctuation">.</span>fulfilled<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token comment">// 开启微任务</span>
      <span class="token function">queueMicrotask</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token punctuation">{</span>
        <span class="token keyword">const</span> nextValue <span class="token operator">=</span> onFulfilled <span class="token operator">?</span> <span class="token function">onFulfilled</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>value<span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>value
        <span class="token function">onNextFulfilled</span><span class="token punctuation">(</span>nextValue<span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>state <span class="token operator">===</span> MyPromise<span class="token punctuation">.</span>rejected<span class="token punctuation">)</span><span class="token punctuation">{</span>
      <span class="token comment">// 开启微任务</span>
      <span class="token function">queueMicrotask</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span><span class="token punctuation">{</span>
        <span class="token keyword">const</span> nextReason <span class="token operator">=</span> onRejected <span class="token operator">?</span> <span class="token function">onRejected</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>reason<span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>reason
        <span class="token function">onNextRejected</span><span class="token punctuation">(</span>nextReason<span class="token punctuation">)</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="proxy"><a href="#proxy" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Proxy" target="_blank" rel="noopener noreferrer">Proxy<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h2 id="reflect"><a href="#reflect" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Reflect" target="_blank" rel="noopener noreferrer">Reflect<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h3 id="ownkeys"><a href="#ownkeys" class="header-anchor">#</a> ownKeys</h3> <p>Reflect.ownKeys(target) return Array</p> <p>返回目标对象属性组成的数组，无论对象的属性是否可枚举</p> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token punctuation">{</span>a<span class="token operator">:</span><span class="token number">1</span><span class="token punctuation">,</span> b<span class="token operator">:</span><span class="token number">2</span><span class="token punctuation">}</span>
Object<span class="token punctuation">.</span><span class="token function">defineProperty</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> <span class="token string">'b'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>enumerable<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">)</span>

Object<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token comment">// a</span>
Reflect<span class="token punctuation">.</span><span class="token function">ownKeys</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token comment">// a b</span>
</code></pre></div><h3 id="has"><a href="#has" class="header-anchor">#</a> has</h3> <p>Reflect.has(target, propertyKey) return Boolean</p> <p>返回目标对象是否存在此属性
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in" target="_blank" rel="noopener noreferrer">同 in 操作符一致<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="generator"><a href="#generator" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Generator" target="_blank" rel="noopener noreferrer">Generator<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2> <h2 id="iterator-2"><a href="#iterator-2" class="header-anchor">#</a> <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Iterator" target="_blank" rel="noopener noreferrer">Iterator<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></h2></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">9/16/2021, 3:28:52 PM</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/learn/js/point.html">知识点</a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.0696c23a.js" defer></script><script src="/assets/js/2.96f039f8.js" defer></script><script src="/assets/js/16.25b14741.js" defer></script>
  </body>
</html>
